import akshare as ak
from connector import mysqlConnectorHelper as mc
import datetime
import SimpleMySqlClass as smc


# 1, get akshare stock data
def get_stock_data_by_symbol(symbol):
    # A 股日频率数据-腾讯
    # "stock_zh_a_hist_tx"  # A 股日频率数据-腾讯

    # "stock_zh_a_daily"  # 获取 A 股历史行情数据(日频)
    stock_qfq_data = ak.stock_zh_a_daily(
        symbol=symbol, adjust="qfq", start_date="20231001", end_date="20231230"
    )
    print("获取 A 股历史行情数据(日频)\n", stock_qfq_data)
    stock_qfq_data = stock_qfq_data.iloc[:, 0:7]
    print("处理之后1：\n", stock_qfq_data)

    # "stock_zh_a_minute"  # 获取 A 股分时历史行情数据(分钟)
    stock_qfq_data = ak.stock_zh_a_minute(symbol=symbol, adjust="qfq", period="30")
    print("获取 A 股分时历史行情数据(分钟)\n", stock_qfq_data)
    stock_qfq_data = stock_qfq_data.iloc[:, 0:7]
    print("处理之后2：\n", stock_qfq_data)

    # print(stock_qfq_data)
    return stock_qfq_data


# 1, get akshare stock data
def get_stock_data_by_code(code):
    # A 股日频率数据-腾讯
    # "stock_zh_a_hist_tx"  # A 股日频率数据-腾讯

    # ak.stock_zh_a_hist_tx()
    ## A 股分时数据
    # "stock_zh_a_hist_min_em"  # 东财-股票分时
    stock_qfq_data = ak.stock_zh_a_hist_min_em(
        symbol=code,
        adjust="qfq",
        period="30",
        # start_date="1979-09-01 09:32:00",
        # end_date="2024-03-01 09:32:00",
    )

    #  start_date: str = "1979-09-01 09:32:00",
    #     end_date: str = "2222-01-01 09:32:00",

    print("获取 A 东财-股票分时(分钟)\n", stock_qfq_data)

    ## A 股日频率数据-东方财富
    # "stock_zh_a_hist"  # A 股日频率数据-东方财富
    # stock_qfq_data = ak.stock_zh_a_hist(
    #     symbol=code, adjust="qfq", start_date="20230101", end_date="20231230"
    # )

    # print("A 股日频率数据-东方财富 ", stock_qfq_data)
    return stock_qfq_data


if __name__ == "__main__":
    symbol = "sz002202"
    get_stock_data_by_symbol(symbol)

    code = "002202"
    # get_stock_data_by_code(code)

    print("main")
